Module Pattern

2025-02-12

The Module pattern helps us to split our code in multiple files and and avoid files with huge lines of code.

1. Introduction

The Module pattern helps us to split our code in multiple files and and avoid files with huge lines of code.

2. Learning Objectives

3. Key Concepts

4. Examples and Practical Cases

// index.js
import { sum, subtract, divide, multiply } from './math.js';

console.log('Sum', sum(1, 2));
console.log('Subtract', subtract(1, 2));
console.log('Divide', divide(1, 2));
console.log('Multiply', multiply(1, 2));
// math.js

export function sum(x, y) {
	return x + y;
}

export function multiply(x, y) {
	return x * y;
} 

export function subtract(x, y) {
	return x - y;
}

export function divide(x, y) {
	return x / y;
}
{
	"name": "node-starter",	
	"version": "0.0.0",
	"type": "module",
	"scripts": {
		"test": "echo \"Error: no test specified\" && exit 1"
	}
}

5. Reflections and Synthesis

Let's talk

Contact

Have a question or a project in mind? Feel free to reach out.

hello@luisluis.dev